<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="RabbitMQ,MQ," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.0" />






<meta name="description" content="1、基本概念 Broker：RabbitMQ服务器，维护一条从生产者到消费者的路线。 Exchange： 消息交换机，指定消息按什么规则，路由到那个队列。 Queue： 消息的载体，每个消息会被投放到一个或多个队列。 Binding： 绑定，他的作用是把exchange和queue按照路由规则绑定起来。 Routing Key：路由关键字，exchange根据这个关键字进行消息投递。 vhost：">
<meta name="keywords" content="RabbitMQ,MQ">
<meta property="og:type" content="article">
<meta property="og:title" content="RabbitMQ随记">
<meta property="og:url" content="https://gitee.com/shuhao/2018/03/21/RabbitMQ随记/index.html">
<meta property="og:site_name" content="Niki">
<meta property="og:description" content="1、基本概念 Broker：RabbitMQ服务器，维护一条从生产者到消费者的路线。 Exchange： 消息交换机，指定消息按什么规则，路由到那个队列。 Queue： 消息的载体，每个消息会被投放到一个或多个队列。 Binding： 绑定，他的作用是把exchange和queue按照路由规则绑定起来。 Routing Key：路由关键字，exchange根据这个关键字进行消息投递。 vhost：">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://gitee.com/blog/images/RabbitMQ/framework.png">
<meta property="og:image" content="https://gitee.com/blog/images/RabbitMQ/scene_1.png">
<meta property="og:image" content="https://gitee.com/blog/images/RabbitMQ/scene_2.png">
<meta property="og:image" content="https://gitee.com/blog/images/RabbitMQ/scene_3.png">
<meta property="og:image" content="https://gitee.com/blog/images/RabbitMQ/scene_3.png">
<meta property="og:updated_time" content="2018-04-05T02:22:09.777Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="RabbitMQ随记">
<meta name="twitter:description" content="1、基本概念 Broker：RabbitMQ服务器，维护一条从生产者到消费者的路线。 Exchange： 消息交换机，指定消息按什么规则，路由到那个队列。 Queue： 消息的载体，每个消息会被投放到一个或多个队列。 Binding： 绑定，他的作用是把exchange和queue按照路由规则绑定起来。 Routing Key：路由关键字，exchange根据这个关键字进行消息投递。 vhost：">
<meta name="twitter:image" content="https://gitee.com/blog/images/RabbitMQ/framework.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Mist',
    sidebar: {"position":"right","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/shuhao/2018/03/21/RabbitMQ随记/"/>





  <title> RabbitMQ随记 | Niki </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb9f0585e406f878cb2f29c89ad3cdb7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Niki</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">天道酬勤</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-categories"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/shuhao/blog/2018/03/21/RabbitMQ随记/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Fang ShuHao">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/head.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Niki">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                RabbitMQ随记
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-03-21T15:24:54+08:00">
                2018-03-21
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/RabbitMQ/" itemprop="url" rel="index">
                    <span itemprop="name">RabbitMQ</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1、基本概念"><a href="#1、基本概念" class="headerlink" title="1、基本概念"></a>1、基本概念</h2><ol>
<li>Broker：RabbitMQ服务器，维护一条从生产者到消费者的路线。</li>
<li>Exchange： 消息交换机，指定消息按什么规则，路由到那个队列。</li>
<li>Queue： 消息的载体，每个消息会被投放到一个或多个队列。</li>
<li>Binding： 绑定，他的作用是把exchange和queue按照路由规则绑定起来。</li>
<li>Routing Key：路由关键字，exchange根据这个关键字进行消息投递。</li>
<li>vhost：虚拟主机，一个broker里可以有多个Vhost，用作不同用户的权限分离。</li>
<li>producer：消息生产者</li>
<li>consumer：消息消费者</li>
<li>channel：消息通道，在客户端的每个连接里，可以建立多个channel</li>
</ol>
<p>RabbitMQ的架构图<br><img src="/blog/images/RabbitMQ/framework.png"></p>
<h2 id="2、Exchange"><a href="#2、Exchange" class="headerlink" title="2、Exchange"></a>2、Exchange</h2><h4 id="2-1-Exchange定义"><a href="#2-1-Exchange定义" class="headerlink" title="2.1 Exchange定义"></a>2.1 Exchange定义</h4><ul>
<li>RabbitMQ的核心思想是producer永远不会直接发送任何消息到queue中，producer只能将消息发送到一个exchange中。</li>
<li>Exchange一边负责接收producer发送的消息，一边负责将消息推送到queue中。</li>
</ul>
<h4 id="2-2、Exchange属性"><a href="#2-2、Exchange属性" class="headerlink" title="2.2、Exchange属性"></a>2.2、Exchange属性</h4><ol>
<li>durable 持久化，</li>
<li>autoDelete 删除标志，当所有队列在完成使用此exchange时，是否删除</li>
</ol>
<h4 id="2-3-Exchange类型"><a href="#2-3-Exchange类型" class="headerlink" title="2.3 Exchange类型"></a>2.3 Exchange类型</h4><ul>
<li>Exchange的类型有四种：fanout，direct， topic， headers</li>
</ul>
<ol>
<li><p>fanout<br>该类型的Exchange会忽略所有的RoutingKey，直接将消息路由到绑定的queue上</p>
</li>
<li><p>direct<br>RabbitMQ默认的Exchange，指定RoutingKey，Exchange会根据RoutingKey将消息路由到相应的queue上。RoutingKey 可以为空，此时和fanout类型的Exchange相似。</p>
</li>
<li><p>topic<br>该类型的Exchange可以根据RoutingKey，将消息路由到对应的queue上，与direct不同的是，topic可以匹配RoutingKey</p>
</li>
<li><p>headers<br>该类型不同于上面三种Exchange，该Exchange根据Message上的头信息路由消息到对应的queue，忽略RoutingKey属性。</p>
</li>
</ol>
<h2 id="3、queue"><a href="#3、queue" class="headerlink" title="3、queue"></a>3、queue</h2><p>queue的三个属性</p>
<ol>
<li><p>durable：队列的属性是否持久化<br>如果队列为持久化，则消息会保存到磁盘，当RabbitMQ重启时，会从磁盘读取为ack的消息重新消费。</p>
</li>
<li><p>exclusive：排他性。只对首次声明它的连接（Connection）可见；会在其连接断开的时候自动删除。<br>对于这一点，首先强调的是<strong><em>首次声明</em></strong>，因为另外一个连接无法声明一个同样的排他性队列；其次是只区别<strong><em>连接（Connection）而不是通道（）Channel</em></strong>，从同一个连接创建的不同的通道可以访问某一个排他性队列；<br>另外RabbitMQ会在连接中断后自动删除该队列，不管该队列是否声明为持久性（durable=true）。因此只要客户端的connection调用了close方法，或者客户端退出，不论队列是否为durable，RabbitMQ都会将这个队列删除。</p>
</li>
<li><p>autoDelete：队列自动删除<br>如果队列声明autoDelete=true，则RabbitMQ会自动删除长时间不使用的队列。<br><strong>注意</strong><br><strong>durable和exclusive属性会有性质上的冲突，同时设置时，exclusive属性生效</strong></p>
</li>
</ol>
<h2 id="4、vhost"><a href="#4、vhost" class="headerlink" title="4、vhost"></a>4、vhost</h2><h2 id="5、RabbitMQ的使用场景"><a href="#5、RabbitMQ的使用场景" class="headerlink" title="5、RabbitMQ的使用场景"></a>5、RabbitMQ的使用场景</h2><h4 id="5-1、单接收场景"><a href="#5-1、单接收场景" class="headerlink" title="5.1、单接收场景"></a>5.1、单接收场景</h4><ul>
<li><p>服务端：声明一个Queue，使用默认的Exchange</p>
</li>
<li><p>客户端：声明和服务端相同的Queue，并且一个客户端监听该Queue</p>
</li>
</ul>
<img src="/blog/images/RabbitMQ/scene_1.png">
<p>这是比较简单的一种消息模式一个客户端去消费生产者产生的消息。</p>
<h4 id="5-2、多接收场景"><a href="#5-2、多接收场景" class="headerlink" title="5.2、多接收场景"></a>5.2、多接收场景</h4><ul>
<li><p>服务端：声明一个Queue，使用默认的Exchange</p>
</li>
<li><p>客户端：声明和服务端相同的Queue，并且多个客户端监听该Queue</p>
</li>
</ul>
<p>注意Queue的属性：durable = true。如客户端崩溃，消息会保存到磁盘，避免消息丢失。</p>
<p>避免一个客户端挂了，无法响应消息，消息丢失，</p>
<h4 id="5-3、发布-订阅模式"><a href="#5-3、发布-订阅模式" class="headerlink" title="5.3、发布/订阅模式"></a>5.3、发布/订阅模式</h4><ul>
<li><p>服务端：声明Exchange</p>
</li>
<li><p>客户端：每个客户端声明一个Queue。并且使用相同的RoutingKey路由到服务端声明的Exchange中<br>这样服务端发送的消息会被路由到所有监听Exchange的Queue上实现了发布订阅的功能。</p>
</li>
</ul>
<p>其实发布订阅也属于多接收场景。<br><img src="/blog/images/RabbitMQ/scene_2.png"><br>多个接收者监听同一个queue，因此消息会被负载到其中一个consumer上。采用的是对consumer个数取余的公平方式。如果某个consumer系统新能能力不行，可能会造成一个现象：大多数的consumer处于空闲状态，而这个系统性能不好的consumer一直处于忙碌状态。这是可以通过设置 prefetch_count = 1 的方式设置接收Consumer在ack之前最多处理一个消息。否则不会发送给他。<strong>这种方式需要手动ack，可能会造成queue的压力；当queue处理能力不足时，需要更多的Consumer来消费消息。</strong><br><figure class="highlight java"><table><tr><td class="code"><pre><span class="line">channel.basic_qos(prefetch_count=<span class="number">1</span>)</span><br></pre></td></tr></table></figure></p>
<img src="/blog/images/RabbitMQ/scene_3.png">
<p>这种方式，多个Consumer监听不同的queue，采用相同的RoutingKey绑定相同的Exchange。达到的正式发布订阅模式。</p>
<img src="/blog/images/RabbitMQ/scene_3.png">
<p>这种方式，通过consumer虽然监听的queue虽然连接相同的Exchange，但是他们绑定的RoutingKey不一样，只有消息的Exchange，RoutingKey，和Queue都相同，才会发送到相应的Consumer上被消费。例如，Message 通过Exchange ，r1只能是到queue1上，最终被consumer1消费。</p>
<h2 id="6、-消息序列化"><a href="#6、-消息序列化" class="headerlink" title="6、 消息序列化"></a>6、 消息序列化</h2><p>RabbitMQ使用的ProtoBuf序列化消息。ProtoBuf的优势有：简单，消息体小，速度快，易于编程等。</p>
<h2 id="7、与Spring整合"><a href="#7、与Spring整合" class="headerlink" title="7、与Spring整合"></a>7、与Spring整合</h2><p>与Spring的整合关键是一下几个步骤</p>
<ol>
<li>创建 ConnectionFactory</li>
<li>创建 RabbitTemplate 用来发送消息</li>
<li>创建 RabbitAdmin 用来定义Exchange ， Queue， </li>
<li>创建 Exchange</li>
<li>创建 Queue</li>
<li>绑定 Exchange 和 Queue</li>
<li>创建 监听容器， 监听器，并配置监听的queue</li>
</ol>
<p><a href="https://gitee.com/shuhao/code/tree/master/RabbitMQ/spboot-rabbitMQ_2">代码中配置可参考git项目</a></p>
<p>Spring中XML配置：<br><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">"http://www.springframework.org/schema/beans"</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:context</span>=<span class="string">"http://www.springframework.org/schema/context"</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="attr">xmlns:p</span>=<span class="string">"http://www.springframework.org/schema/p"</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:rabbit</span>=<span class="string">"http://www.springframework.org/schema/rabbit"</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xsi:schemaLocation</span>=<span class="string">"</span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/beans </span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/beans/spring-beans.xsd </span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/context </span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/context/spring-context.xsd </span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/rabbit </span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/rabbit/spring-rabbit-1.2.xsd"</span>&gt;</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">&lt;!--配置连接--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:connection-factory</span> <span class="attr">id</span>=<span class="string">"asyncBatchConnectionFactory"</span> <span class="attr">host</span>=<span class="string">"192.168.22.111"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">username</span>=<span class="string">"guest"</span> <span class="attr">password</span>=<span class="string">"guest"</span>  <span class="attr">virtual-host</span>=<span class="string">"/"</span> <span class="attr">requested-heartbeat</span>=<span class="string">"60"</span> <span class="attr">channel-cache-size</span>=<span class="string">"5"</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--配置RabbitTemplate--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:template</span> <span class="attr">id</span>=<span class="string">"asyncBatchAmqpTemplate"</span> <span class="attr">connection-factory</span>=<span class="string">"asyncBatchConnectionFactory"</span> <span class="attr">exchange</span>=<span class="string">"myExchange"</span> <span class="attr">routing-key</span>=<span class="string">"foo.bar"</span>/&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--配置RabbitAdmin--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:admin</span> <span class="attr">id</span>=<span class="string">"asyncBatchRabbitAdmin"</span> <span class="attr">connection-factory</span>=<span class="string">"asyncBatchConnectionFactory"</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--配置队列名--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:queue</span> <span class="attr">name</span>=<span class="string">"openimport:async_batch_people_queue"</span> <span class="attr">durable</span>=<span class="string">"true"</span> <span class="attr">auto-delete</span>=<span class="string">"true"</span> <span class="attr">exclusive</span>=<span class="string">"false"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:queue</span> <span class="attr">name</span>=<span class="string">"openimport:async_batch_org_queue"</span> <span class="attr">durable</span>=<span class="string">"true"</span> <span class="attr">auto-delete</span>=<span class="string">"true"</span> <span class="attr">exclusive</span>=<span class="string">"false"</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--配置direct类型exchange--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:direct-exchange</span> <span class="attr">name</span>=<span class="string">"openimport:async_batch_people_exchange"</span> <span class="attr">durable</span>=<span class="string">"false"</span> <span class="attr">auto-delete</span>=<span class="string">"true"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">rabbit:bindings</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">rabbit:binding</span> <span class="attr">queue</span>=<span class="string">"openimport:async_batch_people_queue"</span> <span class="attr">key</span>=<span class="string">"openimport:async_batch_people_queue"</span>&gt;</span><span class="tag">&lt;/<span class="name">rabbit:binding</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">rabbit:bindings</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rabbit:direct-exchange</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:direct-exchange</span> <span class="attr">name</span>=<span class="string">"openimport:async_batch_org_exchange"</span> <span class="attr">durable</span>=<span class="string">"false"</span> <span class="attr">auto-delete</span>=<span class="string">"true"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">rabbit:bindings</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">rabbit:binding</span> <span class="attr">queue</span>=<span class="string">"openimport:async_batch_org_queue"</span> &gt;</span><span class="tag">&lt;/<span class="name">rabbit:binding</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">rabbit:bindings</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rabbit:direct-exchange</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--配置监听--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rabbit:listener-container</span> <span class="attr">connection-factory</span>=<span class="string">"asyncBatchConnectionFactory"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">rabbit:listener</span> <span class="attr">ref</span>=<span class="string">"peopleAsyncBatchConsumer"</span> <span class="attr">queue-names</span>=<span class="string">"openimport:async_batch_people_queue"</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">rabbit:listener</span> <span class="attr">ref</span>=<span class="string">"orgAsyncBatchConsumer"</span> <span class="attr">queue-names</span>=<span class="string">"openimport:async_batch_org_queue"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rabbit:listener-container</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/RabbitMQ/" rel="tag"># RabbitMQ</a>
          
            <a href="/blog/tags/MQ/" rel="tag"># MQ</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/03/13/kafka基本架构/" rel="next" title="kafka基本架构">
                <i class="fa fa-chevron-left"></i> kafka基本架构
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/03/23/Java-9模块化/" rel="prev" title="Java 9模块化">
                Java 9模块化 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNjY5NS8xMzIzMA=="></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/head.jpg"
               alt="Fang ShuHao" />
          <p class="site-author-name" itemprop="name">Fang ShuHao</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives">
                <span class="site-state-item-count">135</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories">
                <span class="site-state-item-count">35</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags">
                <span class="site-state-item-count">93</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、基本概念"><span class="nav-number">1.</span> <span class="nav-text">1、基本概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、Exchange"><span class="nav-number">2.</span> <span class="nav-text">2、Exchange</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-Exchange定义"><span class="nav-number">2.0.1.</span> <span class="nav-text">2.1 Exchange定义</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2、Exchange属性"><span class="nav-number">2.0.2.</span> <span class="nav-text">2.2、Exchange属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-Exchange类型"><span class="nav-number">2.0.3.</span> <span class="nav-text">2.3 Exchange类型</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、queue"><span class="nav-number">3.</span> <span class="nav-text">3、queue</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、vhost"><span class="nav-number">4.</span> <span class="nav-text">4、vhost</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5、RabbitMQ的使用场景"><span class="nav-number">5.</span> <span class="nav-text">5、RabbitMQ的使用场景</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#5-1、单接收场景"><span class="nav-number">5.0.1.</span> <span class="nav-text">5.1、单接收场景</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-2、多接收场景"><span class="nav-number">5.0.2.</span> <span class="nav-text">5.2、多接收场景</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-3、发布-订阅模式"><span class="nav-number">5.0.3.</span> <span class="nav-text">5.3、发布/订阅模式</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6、-消息序列化"><span class="nav-number">6.</span> <span class="nav-text">6、 消息序列化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7、与Spring整合"><span class="nav-number">7.</span> <span class="nav-text">7、与Spring整合</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Fang ShuHao</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  



  
  

  

  

  

  


  

</body>
</html>
